Use case: encryption/decryption in polling mode

Sequence diagram

Encryption/decryption in polling mode

  @startuml
  participant "Application" as App
  participant "CRYP" as CRYP

  note over App,CRYP: Encryption
  App -> CRYP: HAL_CRYP_Encrypt()

  group opt
  note over App,CRYP: Tag generation
  App -> CRYP: HAL_CRYPEx_AESGCM_GenerateAuthTAG()
  note right: **Only for GCM algorithm**
  App -> CRYP: HAL_CRYPEx_AESCCM_GenerateAuthTAG()
  note right: **Only for CCM algorithm**
  end group

  note over App,CRYP: Decryption
  App -> CRYP: HAL_CRYP_Decrypt()

  group opt
  note over App,CRYP: Tag generation
  App -> CRYP: HAL_CRYPEx_AESGCM_GenerateAuthTAG()
  note right: **Only for GCM algorithm**
  App -> CRYP: HAL_CRYPEx_AESCCM_GenerateAuthTAG()
  note right: **Only for CCM algorithm**
  end group
  @enduml

Code snippet

HAL1

HAL2

/* Encryption */
HAL_CRYP_Encrypt(&hcryp, Plaintext, PLAINTEXT_SIZE,
                 EncryptedText, TIMEOUT_VALUE);

/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
                                        TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
                                        TIMEOUT_VALUE);

/* Decryption */
HAL_CRYP_Decrypt(&hcryp,Ciphertext , PLAINTEXT_SIZE,
                 DecryptedText, TIMEOUT_VALUE);

/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
                                        TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
                                        TIMEOUT_VALUE);
/* Encryption */
HAL_CRYP_Encrypt(&hcryp, Plaintext, PLAINTEXT_SIZE ,
                       EncryptedText, TIMEOUT_VALUE);

/* Only for GCM algorithm */
HAL_CRYP_GCM_GenerateAuthTAG(&hahcryps,TAG,
                                     TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYP_CCM_GenerateAuthTAG(&hcryp,TAG,
                                     TIMEOUT_VALUE);

/* Decryption */
HAL_CRYP_Decrypt(&hcryp, Ciphertext, PLAINTEXT_SIZE ,
                        DecryptedText, TIMEOUT_VALUE);

/* Only for GCM algorithm */
HAL_CRYP_GCM_GenerateAuthTAG(&hcryp,TAG,
                                      TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYP_CCM_GenerateAuthTAG(&hcryp,TAG,
                                     TIMEOUT_VALUE);

Key changes

  1. Tag generation APIs are renamed from HAL_CRYPEx_AES* to HAL_CRYP_* for GCM and CCM algorithms.

  2. Polling-mode encryption and decryption APIs keep the same names (HAL_CRYP_Encrypt() / HAL_CRYP_Decrypt()).